using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Boomlagoon.JSON;

public class LevelStateParser {
	public static void parseLevelState (JSONObject levelStateJsonObj , LevelState levelState)
	{
		Dictionary<string,CellState> cellStates = new Dictionary<string,CellState>();
		levelState.SetCellStates(cellStates);

		JSONObject cellStatesJsonObj = levelStateJsonObj.GetObject("cellStates");

		foreach (KeyValuePair<string,JSONValue> cellStatePair in cellStatesJsonObj)
		{
			string cellStateId = cellStatePair.Key;
			JSONObject cellStateJsonObj = cellStatePair.Value.Obj;

			CellState cellState = new CellState();
			CellStateParser.parseCellState(cellStateJsonObj , cellState);

			if (cellState.X < levelState.XMin)
			{
				levelState.XMin = cellState.X;
			}

			if (cellState.X > levelState.XMax)
			{
				levelState.XMax = cellState.X;
			}

			if (cellState.Y < levelState.YMin)
			{
				levelState.YMin = cellState.Y;
			}

			if (cellState.Y > levelState.YMax)
			{
				levelState.YMax = cellState.Y;
			}

			if (cellState.Z < levelState.ZMin)
			{
				levelState.ZMin = cellState.Z;
			}

			if (cellState.Z > levelState.ZMax)
			{
				levelState.ZMax = cellState.Z;
			}
			
			cellStates.Add(cellStateId , cellState);
		}
	}
}
